//
// Created by harrybao on 2019/4/3.
//

#include "util_time.h"

//timeval UtilTime::tv_;
//timeval UtilTime::ttv_;
const std::chrono::time_point<high_resolution_clock> UtilTime::start_point_ = high_resolution_clock::now();
std::chrono::time_point<high_resolution_clock> UtilTime::pre_point_ = high_resolution_clock::now();

/*
long UtilTime::GetDeltaTimeMillionSec()
{
    ttv_ = tv_;
    gettimeofday(&tv_, nullptr);
    return (tv_.tv_sec - ttv_.tv_sec) * 1000 + (tv_.tv_usec - ttv_.tv_usec) / 1000;
}
*/

void UtilTime::Init()
{
    //gettimeofday(&tv_, nullptr);
    pre_point_ = high_resolution_clock::now();
}

long long UtilTime::GetPassedSeconds()
{
    return duration_cast<std::chrono::seconds>(high_resolution_clock::now() - start_point_).count();
}

long long UtilTime::GetPassedMilliseconds()
{
    return duration_cast<std::chrono::milliseconds>(high_resolution_clock::now() - start_point_).count();
}

long long UtilTime::GetPassedMicroseconds()
{
    return duration_cast<std::chrono::microseconds>(high_resolution_clock::now() - start_point_).count();
}

long long UtilTime::GetDeltaSeconds()
{
    const auto &now_point = high_resolution_clock::now();
    auto delta_time = duration_cast<std::chrono::seconds>(now_point - pre_point_).count();
    pre_point_ = now_point;
    return delta_time;
}

long long UtilTime::GetDeltaMilliseconds()
{
    const auto &now_point = high_resolution_clock::now();
    auto delta_time = duration_cast<std::chrono::milliseconds>(now_point - pre_point_).count();
    pre_point_ = now_point;
    return delta_time;
}

long long UtilTime::GetDeltaMicroseconds()
{
    const auto &now_point = high_resolution_clock::now();
    auto delta_time = duration_cast<std::chrono::microseconds>(now_point - pre_point_).count();
    pre_point_ = now_point;
    return delta_time;
}